﻿--军需官

--#include "data\language\LangCode.txt" once --语言包 
--#include "data\config\activityconfig\Dart\DartConfig.lua"  once  --基本设置
--#include "data\functions\Activity\Dart\ApplyDartCommon.lua"
--#include "data\functions\FuBenNpcFunc\FubenCommonFunc.lua" once
--#include "data\config\activity\StdActivityCfg.lua" once
--#include "data\functions\Quest\QuestCommon.lua" once 			--任务相关方法

NpcDialog[81] = {}
NpcDialog[81].main = function(sysarg)
	local sData = OpenDartDialog(sysarg);
	if not sData then
		return;
	end
	
	Actor.openDialogs(sysarg, enLinkYuanbaoWnd, sData);
end


-- 购买保险
NpcDialog[81].buyinsurance = function(sysarg)
	local var = Actor.getStaticVar(sysarg);
	local bcHandle = var.bcHandle;
	if var.ybstate == 1 then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.bc00010, ttFlyTip)
		return 
	end
	
	if not var.buybx then
		var.buybx = 1;
	else
		var.buybx = nil;
	end
	return NpcDialog[81].main(sysarg);
end

-- 刷新品质
NpcDialog[81].refleshquality = function(sysarg)
	local cfg = StdActivityCfg[4];
	local var = Actor.getStaticVar(sysarg);
	if var.ybstate == 1 then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.bc00010, ttFlyTip)
		return 
	end
	
	local bcpz = var.bcpz;
	if not bcpz then bcpz = 1; end
	
	local pzxstms = var.pzxstms;
	if not pzxstms then pzxstms = 0; end

	tBiaoche = cfg.tBiaoche;
	if (bcpz + 1) > #tBiaoche then
		local name = string.format("{color;%s;%s}", tBiaoche[bcpz].color, tBiaoche[bcpz].monName);
		Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.bc00008, name), ttFlyTip);
		return NpcDialog[81].main(sysarg);
	end
	
	local tYBL = cfg.tYBL;
	if Actor.removeItem(sysarg, tYBL.id, tYBL.count, -1, -1, -1, "扣除运镖令") ~= tYBL.count then
		Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.bc00004, tYBL.name, tYBL.count), ttFlyTip);
		return NpcDialog[81].main(sysarg);
	end
	
	var.pzxstms = pzxstms + 1;
	if math.random(10000) > tBiaoche[bcpz + 1].freshRate then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.bc00003, ttFlyTip);
		return NpcDialog[81].main(sysarg);
	end
	
	var.bcpz = bcpz + 1;
	local name = string.format("{color;%s;%s}", tBiaoche[var.bcpz].color, tBiaoche[var.bcpz].monName);
	Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.bc00002, name), ttFlyTip);
	return NpcDialog[81].main(sysarg);
end

-- 开始护送
NpcDialog[81].startdrat = function(sysarg)
	local cfg = StdActivityCfg[4];
	local var = Actor.getStaticVar(sysarg)

	if var.ybstate == 1 then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.bc00010, ttFlyTip)
		return 
	end
	
	local buybx = var.buybx;
	if not buybx then buybx = 0; end
	if buybx == 1 then
		if Actor.changeMoney(sysarg, mtYuanbao, -cfg.insurance, LogIds.ybBuyInsuranceConsume, Lang.LogTips.yb049) == false then
			Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.bc00009, cfg.insurance), ttFlyTip);
			var.buybx = nil;
			return NpcDialog[81].main(sysarg);
		end
		Actor.sendTipmsg(sysarg, string.format(Lang.ScriptTips.bc00001, cfg.insurance, cfg.tAwardPercent[4]*100), ttFlyTip);
	end
	
	StartDartToDest(sysarg)
	Actor.closeNPCDialog(sysarg)	
end
